package com.unieagle.exam.model;

import org.json.JSONObject;

public final class TaskResult
{
    private final int SUCCESS = 200;
    
    private final int INVALID_TOKEN = 400;

    private int errorCode;

    private String message;

    private JSONObject data;

    private TaskResult()
    {

    }

    public static TaskResult parse(JSONObject obj)
    {
        TaskResult result = new TaskResult();
        result.setErrorCode(obj.optInt("result_code"));
        result.setMessage(obj.optString("msg"));
        result.setData(obj.optJSONObject("data"));
        return result;
    }

    public boolean isSuccess()
    {
        return errorCode == SUCCESS;
    }
    
    public boolean isInvalidToken() {
    	return errorCode == INVALID_TOKEN;
    }

    public int getErrorCode()
    {
        return errorCode;
    }

    public void setErrorCode(int errorCode)
    {
        this.errorCode = errorCode;
    }

    public String getMessage()
    {
        return message;
    }

    public void setMessage(String message)
    {
        this.message = message;
    }

    public JSONObject getData()
    {
        return data;
    }

    public void setData(JSONObject data)
    {
        this.data = data;
    }

}
